<?php
/**
 * 开发商后台-配置数据库的Entity基础类
 * Created by PhpStorm.
 * User: wangx08
 * Date: 2015-03-28
 * Time: 16:58
 */

namespace common\entities;


class ConfigEntity extends BaseEntity {

    /**
     * @return \yii\db\connection
     */
    public static function getDb(){
        return \Yii::$app->cdb; //config/web中配置的链接
    }
    
    /**
     * 获取数据库当前时间截
     * @return int
     */
    public static function getDbNowTimestamp(){
    	$db = self::getDb();
    	$timestamp = $db->createCommand("SELECT UNIX_TIMESTAMP() AS `timestamp`")->queryScalar();//取数据库时间
    	return $timestamp;
    }
    
    /**
     * 获取数据库当前时间(如2015-05-22 12:00:00)
     * @return string
     */
    public static function getDbNowDate(){
    	$db = self::getDb();
    	$timestamp = $db->createCommand("SELECT UNIX_TIMESTAMP() AS `timestamp`")->queryScalar();//取数据库时间
    	return date("Y-m-d H:i:s",$timestamp);
    }
}